#pragma once
#ifndef _MQTT_SUB__H
#define _MQTT_SUB__H
#include <Theron/Theron.h>
#include "singleton.h"
#include "CMQTTClient.h"
#include <string>
#include "DataCenter.h"


class CMQTTSub : public Theron::Actor
{
public:
	int m_id;
	Theron::Framework t_framwork;
	friend class Singleton<CMQTTSub>;
	CMQTTSub() : Theron::Actor(t_framwork) {

	}
	explicit CMQTTSub(Theron::Framework &framwork) : Theron::Actor(framwork)
	{
		RegisterHandler(this, &CMQTTSub::handleInt);
	}

	void start();
	int setID(int id);
	int getID();

	int sendString2ThreadbyID(std::string data, int ID);

	void static delivered(void *context, MQTTClient_deliveryToken dt);
	int static msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message);
	void static connlost(void *context, char *cause);

	void test();
	void handleInt(const int& item, const Theron::Address from);
private:
	CMQTTClent client;

	void initMQTT();
};

#endif